/**
 * 时间单位常量定义
 */
export const TIME_UNITS: any = {
  // 基础单位定义（毫秒）
  MILLISECOND: 1,
  SECOND: 1000,
  MINUTE: 60 * 1000,
  HOUR: 60 * 60 * 1000,
  DAY: 24 * 60 * 60 * 1000,
  WEEK: 7 * 24 * 60 * 60 * 1000,
  MONTH: 30 * 24 * 60 * 60 * 1000, // 近似值
  YEAR: 365 * 24 * 60 * 60 * 1000, // 近似值

  // 单位映射表（毫秒数）
  MILLISECONDS: {
    MILLISECOND: 1,
    SECOND: 1000,
    MINUTE: 60 * 1000,
    HOUR: 60 * 60 * 1000,
    DAY: 24 * 60 * 60 * 1000,
    WEEK: 7 * 24 * 60 * 60 * 1000,
    MONTH: 30 * 24 * 60 * 60 * 1000,
    YEAR: 365 * 24 * 60 * 60 * 1000,
  },

  // 秒数映射表
  SECONDS: {
    SECOND: 1,
    MINUTE: 60,
    HOUR: 60 * 60,
    DAY: 24 * 60 * 60,
    WEEK: 7 * 24 * 60 * 60,
    MONTH: 30 * 24 * 60 * 60,
    YEAR: 365 * 24 * 60 * 60,
  },

  // 分钟数映射表
  MINUTES: {
    MINUTE: 1,
    HOUR: 60,
    DAY: 24 * 60,
    WEEK: 24 * 7 * 60,
    MONTH: 24 * 30 * 60,
    YEAR: 24 * 365 * 60,
  },

  // 小时数映射表
  HOURS: {
    MINUTE: 1 / 60,
    HOUR: 1,
    DAY: 24,
    WEEK: 24 * 7,
    MONTH: 24 * 30,
    YEAR: 24 * 365,
  },

  // 多语言单位显示
  DISPLAY: {
    CHINESE: {
      MILLISECOND: '毫秒',
      SECOND: '秒',
      MINUTE: '分钟',
      HOUR: '小时',
      DAY: '天',
      WEEK: '周',
      MONTH: '月',
      YEAR: '年',
    },
    ENGLISH: {
      MILLISECOND: 'millisecond',
      SECOND: 'second',
      MINUTE: 'minute',
      HOUR: 'hour',
      DAY: 'day',
      WEEK: 'week',
      MONTH: 'month',
      YEAR: 'year',
    },
    SHORT: {
      MILLISECOND: 'ms',
      SECOND: 's',
      MINUTE: 'm',
      HOUR: 'h',
      DAY: 'd',
      WEEK: 'w',
      MONTH: 'M',
      YEAR: 'Y',
    },
    // 复数形式
    CHINESE_PLURAL: {
      MILLISECOND: '毫秒',
      SECOND: '秒',
      MINUTE: '分钟',
      HOUR: '小时',
      DAY: '天',
      WEEK: '周',
      MONTH: '月',
      YEAR: '年',
    },
    ENGLISH_PLURAL: {
      MILLISECOND: 'milliseconds',
      SECOND: 'seconds',
      MINUTE: 'minutes',
      HOUR: 'hours',
      DAY: 'days',
      WEEK: 'weeks',
      MONTH: 'months',
      YEAR: 'years',
    },
  },

  // 时间单位分类
  CATEGORIES: {
    // 按时间跨度分类
    SPAN: {
      SHORT_TERM: ['MILLISECOND', 'SECOND', 'MINUTE', 'HOUR'],
      MEDIUM_TERM: ['DAY', 'WEEK'],
      LONG_TERM: ['MONTH', 'YEAR'],
    },
    // 按精度分类
    PRECISION: {
      HIGH: ['MILLISECOND', 'SECOND'],
      MEDIUM: ['MINUTE', 'HOUR'],
      LOW: ['DAY', 'WEEK', 'MONTH', 'YEAR'],
    },
    // 常用组合
    COMMON: {
      TIME: ['HOUR', 'MINUTE', 'SECOND'],
      DATE: ['YEAR', 'MONTH', 'DAY'],
      FULL: ['YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', 'SECOND'],
    },
  },

  // 格式化配置
  FORMAT: {
    // 自动格式化阈值配置
    AUTO_THRESHOLDS: [
      { unit: 'MILLISECOND', max: 1000, precision: 0 },
      { unit: 'SECOND', max: 60, precision: 1 },
      { unit: 'MINUTE', max: 60, precision: 1 },
      { unit: 'HOUR', max: 24, precision: 1 },
      { unit: 'DAY', max: 7, precision: 1 },
      { unit: 'WEEK', max: 4, precision: 1 },
      { unit: 'MONTH', max: 12, precision: 1 },
      { unit: 'YEAR', max: Infinity, precision: 1 },
    ],

    // 精确格式化配置
    PRECISE: {
      UNITS: ['YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', 'SECOND'],
      SEPARATORS: {
        CHINESE: ' ',
        ENGLISH: ' ',
        SHORT: ' ',
      },
      MAX_UNITS: 3,
    },

    // 人性化时间显示配置
    HUMANIZE: {
      THRESHOLDS: [
        { unit: 'SECOND', max: 45, text: '刚刚' },
        { unit: 'MINUTE', max: 45, text: '{value}分钟前' },
        { unit: 'HOUR', max: 22, text: '{value}小时前' },
        { unit: 'DAY', max: 7, text: '{value}天前' },
        { unit: 'WEEK', max: 4, text: '{value}周前' },
        { unit: 'MONTH', max: 12, text: '{value}月前' },
        { unit: 'YEAR', max: Infinity, text: '{value}年前' },
      ],
    },
  },

  // 常用时间常量
  COMMON: {
    // 常用时间间隔（毫秒）
    INTERVALS: {
      HALF_MINUTE: 30 * 1000,
      ONE_MINUTE: 60 * 1000,
      THREE_MINUTES: 3 * 60 * 1000,
      FIVE_MINUTES: 5 * 60 * 1000,
      TEN_MINUTES: 10 * 60 * 1000,
      HALF_HOUR: 30 * 60 * 1000,
      ONE_HOUR: 60 * 60 * 1000,
      TWO_HOURS: 2 * 60 * 60 * 1000,
      SIX_HOURS: 6 * 60 * 60 * 1000,
      HALF_DAY: 12 * 60 * 60 * 1000,
      ONE_DAY: 24 * 60 * 60 * 1000,
      TWO_DAYS: 2 * 24 * 60 * 60 * 1000,
      ONE_WEEK: 7 * 24 * 60 * 60 * 1000,
      TWO_WEEKS: 14 * 24 * 60 * 60 * 1000,
      ONE_MONTH: 30 * 24 * 60 * 60 * 1000,
      THREE_MONTHS: 90 * 24 * 60 * 60 * 1000,
      HALF_YEAR: 182 * 24 * 60 * 60 * 1000,
      ONE_YEAR: 365 * 24 * 60 * 60 * 1000,
    },

    // 时间范围
    RANGES: {
      TODAY: 24 * 60 * 60 * 1000,
      RECENT_WEEK: 7 * 24 * 60 * 60 * 1000,
      RECENT_MONTH: 30 * 24 * 60 * 60 * 1000,
      RECENT_YEAR: 365 * 24 * 60 * 60 * 1000,
    },
  },
}

/**
 * 时间单位类型定义
 */
export type TimeUnit = keyof typeof TIME_UNITS.MILLISECONDS
export type TimeInterval = keyof typeof TIME_UNITS.COMMON.INTERVALS
export type TimeUnitCategory = keyof typeof TIME_UNITS.CATEGORIES.SPAN
export type TimeLanguage = keyof typeof TIME_UNITS.DISPLAY
export enum TimeFormat {
  Auto = 'auto',
  Precise = 'precise',
  Humanize = 'humanize',
}

export const WEEKDAYS_CHINESE: string[] = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日']
